Skip to content

Don't ICE on pending obligations from deep normalization in a loop #140021

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

compiler-errors
Copy link
Member

See the comment I left inline in compiler/rustc_trait_selection/src/traits/normalize.rs.

Fixes #133868

r? lcnr

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 18, 2025
@rustbot
Copy link
Collaborator

rustbot commented Apr 18, 2025

This PR changes a file inside tests/crashes. If a crash was fixed, please move into the corresponding ui subdir and add 'Fixes #' to the PR description to autoclose the issue upon merge.

Comment on lines 78 to 82
let mut errors = fulfill_cx.select_all_or_error(self.infcx);
// Drain pending obligations too, since deep normalization may happen
// in a loop and we don't want to trigger the assertion on the next
// iteration due to pending obligations we've left over.
errors.extend(fulfill_cx.collect_remaining_errors(self.infcx));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, fn select_all_or_error is currently implemented as

    fn select_all_or_error(&mut self, infcx: &InferCtxt<'tcx>) -> Vec<E> {
        let errors = self.select_where_possible(infcx);
        if !errors.is_empty() {
            return errors;
        }

        self.collect_remaining_errors(infcx)
    }

it feels a bit footgunny to not add the overflowing obligations if there are other errors. I think changing the if errors.is_empty() branch to also add the remaining errors would be better 🤔

Copy link
Contributor

@lcnr lcnr Apr 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or no, in case select_where_possible returns an error, we want to ignore overflow and ambiguity errors. I think we also want to ignore these ambiguity errors here, so maybe change this to

            let errors = fulfill_cx.select_all_or_error(self.infcx);
            if errors.is_empty() {
                Ok(self.infcx.resolve_vars_if_possible(value))
            } else {
                // In case normalization resulted in an error, we want to
                // drain any still ambiguous goal to avoid triggering the
                // assertion on the next iteration.
                let _ = fulfill_cx.collect_remaining_errors(self.infcx));
                Err(errors)
            }

Copy link
Contributor

@lcnr lcnr Apr 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alternatively we could drop the remaining obligations in the !errors.is_empty() branch in select_all_or_error itself? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alternatively we could drop the remaining obligations in the !errors.is_empty() branch in select_all_or_error itself? 🤔

Hm, feels like a much larger and more subtle change. I'd rather keep it located to deep normalization.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or no, in case select_where_possible returns an error, we want to ignore overflow and ambiguity errors. I think we also want to ignore these ambiguity errors here, so maybe change this to [...]

Functionally equivalent to what I have right now, but I guess alright.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionally equivalent to what I have right now, but I guess alright.

Correction -- not functionally equivalent, but doesn't matter for UI tests. I originally had let _ = fulfill_cx.collect_remaining_errors(self.infcx)) on the good path of deep norm too, but it felt spooky. I guess it's fine though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ICE: deeply_normalize should not be called with pending obligations
3 participants